Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 156 |
|
0.00% |
0 / 99 |
|
0.00% |
0 / 227 |
|
0.00% |
0 / 18 |
CRAP | |
0.00% |
0 / 1 |
| DAO | |
0.00% |
0 / 156 |
|
0.00% |
0 / 99 |
|
0.00% |
0 / 227 |
|
0.00% |
0 / 18 |
3192 | |
0.00% |
0 / 1 |
| getParentColumn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| newDataObject | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| insert | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| update | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMany | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getByKey | |
0.00% |
0 / 4 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getCount | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fromRow | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
20 | |||
| deleteEmailTemplatesByLocale | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| defaultTemplateIsInstalled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMainEmailTemplatesFilename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| installEmailTemplates | |
0.00% |
0 / 24 |
|
0.00% |
0 / 23 |
|
0.00% |
0 / 97 |
|
0.00% |
0 / 1 |
132 | |||
| installEmailTemplateLocaleData | |
0.00% |
0 / 32 |
|
0.00% |
0 / 26 |
|
0.00% |
0 / 93 |
|
0.00% |
0 / 1 |
156 | |||
| installAlternateEmailTemplates | |
0.00% |
0 / 25 |
|
0.00% |
0 / 14 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
56 | |||
| renameApplicationVariables | |
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| variablesToRename | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUniqueKey | |
0.00% |
0 / 11 |
|
0.00% |
0 / 9 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @file classes/emailTemplate/DAO.php |
| 4 | * |
| 5 | * Copyright (c) 2014-2021 Simon Fraser University |
| 6 | * Copyright (c) 2000-2021 John Willinsky |
| 7 | * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. |
| 8 | * |
| 9 | * @class DAO |
| 10 | * |
| 11 | * @brief Read and write email templates to the database. |
| 12 | */ |
| 13 | |
| 14 | namespace PKP\emailTemplate; |
| 15 | |
| 16 | use APP\core\Application; |
| 17 | use APP\facades\Repo; |
| 18 | use Exception; |
| 19 | use Illuminate\Support\Facades\DB; |
| 20 | use Illuminate\Support\LazyCollection; |
| 21 | use Illuminate\Support\Str; |
| 22 | use PKP\core\EntityDAO; |
| 23 | use PKP\core\PKPApplication; |
| 24 | use PKP\db\DAORegistry; |
| 25 | use PKP\db\XMLDAO; |
| 26 | use PKP\facades\Locale; |
| 27 | use PKP\site\Site; |
| 28 | use PKP\site\SiteDAO; |
| 29 | |
| 30 | /** |
| 31 | * @template T of EmailTemplate |
| 32 | * |
| 33 | * @extends EntityDAO<T> |
| 34 | */ |
| 35 | class DAO extends EntityDAO |
| 36 | { |
| 37 | /** @copydoc EntityDAO::$schema */ |
| 38 | public $schema = \PKP\services\PKPSchemaService::SCHEMA_EMAIL_TEMPLATE; |
| 39 | |
| 40 | /** @copydoc EntityDAO::$table */ |
| 41 | public $table = 'email_templates'; |
| 42 | |
| 43 | /** @copydoc EntityDAO::$settingsTable */ |
| 44 | public $settingsTable = 'email_templates_settings'; |
| 45 | |
| 46 | public $defaultTable = 'email_templates_default_data'; |
| 47 | |
| 48 | /** @copydoc EntityDAO::$primaryKeyColumn */ |
| 49 | public $primaryKeyColumn = 'email_id'; |
| 50 | |
| 51 | /** @copydoc EntityDAO::$primaryTableColumns */ |
| 52 | public $primaryTableColumns = [ |
| 53 | 'id' => 'email_id', |
| 54 | 'key' => 'email_key', |
| 55 | 'alternateTo' => 'alternate_to', |
| 56 | 'contextId' => 'context_id', |
| 57 | 'enabled' => 'enabled', |
| 58 | ]; |
| 59 | |
| 60 | /** |
| 61 | * Get the parent object ID column name |
| 62 | */ |
| 63 | public function getParentColumn(): string |
| 64 | { |
| 65 | return 'context_id'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Instantiate a new DataObject |
| 70 | */ |
| 71 | public function newDataObject(): EmailTemplate |
| 72 | { |
| 73 | return app(EmailTemplate::class); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @copydoc EntityDAO::insert() |
| 78 | * |
| 79 | * Custom email templates will need to generate a unique key, |
| 80 | * but the key will be set when this template is a customization |
| 81 | * of a default template. |
| 82 | * |
| 83 | * @throws Exception |
| 84 | * |
| 85 | * @return string The email template key |
| 86 | */ |
| 87 | public function insert(EmailTemplate $object): string |
| 88 | { |
| 89 | if (!$object->getData('key')) { |
| 90 | $object->setData('key', $this->getUniqueKey($object)); |
| 91 | } |
| 92 | parent::_insert($object); |
| 93 | return $object->getData('key'); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @copydoc EntityDAO::update() |
| 98 | */ |
| 99 | public function update(EmailTemplate $object) |
| 100 | { |
| 101 | parent::_update($object); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @copydoc EntityDAO::delete() |
| 106 | */ |
| 107 | public function delete(EmailTemplate $emailTemplate) |
| 108 | { |
| 109 | parent::_delete($emailTemplate); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get a collection of Email Templates matching the configured query |
| 114 | * |
| 115 | * @return LazyCollection<int,T> |
| 116 | */ |
| 117 | public function getMany(Collector $query): LazyCollection |
| 118 | { |
| 119 | $rows = $query |
| 120 | ->getQueryBuilder() |
| 121 | ->get(); |
| 122 | |
| 123 | return LazyCollection::make(function () use ($rows) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 126 | } |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Get a single email template that matches the given key |
| 132 | */ |
| 133 | public function getByKey(int $contextId, string $key): ?EmailTemplate |
| 134 | { |
| 135 | $results = Repo::emailTemplate()->getCollector($contextId) |
| 136 | ->filterByKeys([$key]) |
| 137 | ->getMany(); |
| 138 | |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Get the number of announcements matching the configured query |
| 144 | */ |
| 145 | public function getCount(Collector $query): int |
| 146 | { |
| 147 | return $query |
| 148 | ->getQueryBuilder() |
| 149 | ->getCountForPagination(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Retrieve template together with data from the email_template_default_data |
| 154 | * |
| 155 | * @copydoc EntityDAO::fromRow() |
| 156 | */ |
| 157 | public function fromRow(object $row): EmailTemplate |
| 158 | { |
| 159 | /** @var EmailTemplate $emailTemplate */ |
| 160 | $emailTemplate = parent::fromRow($row); |
| 161 | $schema = $this->schemaService->get($this->schema); |
| 162 | $contextDao = Application::getContextDAO(); |
| 163 | |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 165 | ? DB::table('site')->first()->supported_locales |
| 166 | : DB::table($contextDao->settingsTableName) |
| 167 | ->where($contextDao->primaryKeyColumn, $row->context_id) |
| 168 | ->where('setting_name', 'supportedLocales') |
| 169 | ->value('setting_value'); |
| 170 | |
| 171 | $rows = DB::table($this->defaultTable) |
| 172 | ->where('email_key', '=', $emailTemplate->getData('key')) |
| 173 | ->whereIn('locale', json_decode($supportedLocalesJson, true)) |
| 174 | ->get(); |
| 175 | |
| 176 | $props = ['name', 'subject', 'body']; |
| 177 | |
| 178 | $rows->each(function ($row) use ($emailTemplate, $schema, $props) { |
| 179 | foreach ($props as $prop) { |
| 180 | // Don't allow default data to override custom template data |
| 181 | if ($emailTemplate->getData($prop, $row->locale)) { |
| 182 | continue; |
| 183 | } |
| 184 | $emailTemplate->setData( |
| 185 | $prop, |
| 186 | $this->convertFromDB( |
| 187 | $row->{$prop}, |
| 188 | $schema->properties->{$prop}->type |
| 189 | ), |
| 190 | $row->locale |
| 191 | ); |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | return $emailTemplate; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Delete all email templates for a specific locale. |
| 200 | */ |
| 201 | public function deleteEmailTemplatesByLocale(string $locale) |
| 202 | { |
| 203 | DB::table($this->settingsTable)->where('locale', $locale)->delete(); |
| 204 | DB::table($this->defaultTable)->where('locale', $locale)->delete(); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Check if a template exists with the given email key for a journal/ |
| 209 | * conference/... |
| 210 | * |
| 211 | * |
| 212 | * @return bool |
| 213 | */ |
| 214 | public function defaultTemplateIsInstalled(string $key) |
| 215 | { |
| 216 | return DB::table($this->defaultTable)->where('email_key', $key)->exists(); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get the main email template path and filename. |
| 221 | * |
| 222 | * TODO add to the Repository |
| 223 | */ |
| 224 | public function getMainEmailTemplatesFilename() |
| 225 | { |
| 226 | return 'registry/emailTemplates.xml'; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Install email templates from an XML file. |
| 231 | * |
| 232 | * @param string $templatesFile Filename to install |
| 233 | * @param array $locales List of locales to install data for |
| 234 | * @param string|null $emailKey Optional name of single email key to install, |
| 235 | * skipping others |
| 236 | * @param bool $skipExisting If true, do not install email templates |
| 237 | * that already exist in the database |
| 238 | * |
| 239 | */ |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 249 | return false; |
| 250 | } |
| 251 | |
| 252 | // if locales is empty, it will use the site's installed locales |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Install email template contents from an XML file. |
| 290 | * |
| 291 | * @param string $templatesFile Filename to install |
| 292 | * @param array $locales List of locales to install data for |
| 293 | * @param string|null $emailKey Optional name of single email key to install, |
| 294 | * skipping others |
| 295 | * |
| 296 | */ |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Installs the "extra" email templates for a context |
| 347 | * |
| 348 | * These are default email templates that are not the default email |
| 349 | * template for a particular mailable. They are extra templates listed |
| 350 | * alongside the default template for this mailable. |
| 351 | * |
| 352 | * These templates are defined by the presence of the `alternateTo` |
| 353 | * attribute in the email templates XML file. For them to appear in the |
| 354 | * UI, they must have an entry in the `email_templates` database. |
| 355 | */ |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 361 | throw new Exception('Unable to install email templates.'); |
| 362 | } |
| 363 | |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * @param string $localizedData email template's localized subject or body |
| 397 | */ |
| 398 | protected function renameApplicationVariables(string $localizedData): string |
| 399 | { |
| 400 | $map = $this->variablesToRename(); |
| 401 | if (empty($map)) { |
| 402 | return $localizedData; |
| 403 | } |
| 404 | |
| 405 | $variables = []; |
| 406 | $replacements = []; |
| 407 | foreach ($map as $key => $value) { |
| 408 | $variables[] = '/\{\$' . $key . '\}/'; |
| 409 | $replacements[] = '{$' . $value . '}'; |
| 410 | } |
| 411 | |
| 412 | return preg_replace($variables, $replacements, $localizedData); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Override this function on an application level to rename app-specific template variables |
| 417 | * |
| 418 | * Example: ['contextName' => 'journalName'] |
| 419 | */ |
| 420 | protected function variablesToRename(): array |
| 421 | { |
| 422 | return []; |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Gets a unique key for an email template |
| 427 | * |
| 428 | * Use this to generate a unique key before adding a template to the |
| 429 | * database. |
| 430 | */ |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 437 | $key = uniqid(); |
| 438 | } |
| 439 | |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 445 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 446 | $i++; |
| 447 | } |
| 448 | |
| 449 | return $key; |
| 450 | } |
| 451 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 123 | return LazyCollection::make(function () use ($rows) { |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 126 | } |
| 127 | }); |
| 123 | return LazyCollection::make(function () use ($rows) { |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 126 | } |
| 127 | }); |
| 123 | return LazyCollection::make(function () use ($rows) { |
| 124 | foreach ($rows as $row) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 126 | } |
| 127 | }); |
| 214 | public function defaultTemplateIsInstalled(string $key) |
| 215 | { |
| 216 | return DB::table($this->defaultTable)->where('email_key', $key)->exists(); |
| 217 | } |
| 107 | public function delete(EmailTemplate $emailTemplate) |
| 108 | { |
| 109 | parent::_delete($emailTemplate); |
| 110 | } |
| 201 | public function deleteEmailTemplatesByLocale(string $locale) |
| 202 | { |
| 203 | DB::table($this->settingsTable)->where('locale', $locale)->delete(); |
| 204 | DB::table($this->defaultTable)->where('locale', $locale)->delete(); |
| 205 | } |
| 157 | public function fromRow(object $row): EmailTemplate |
| 158 | { |
| 159 | /** @var EmailTemplate $emailTemplate */ |
| 160 | $emailTemplate = parent::fromRow($row); |
| 161 | $schema = $this->schemaService->get($this->schema); |
| 162 | $contextDao = Application::getContextDAO(); |
| 163 | |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 165 | ? DB::table('site')->first()->supported_locales |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 165 | ? DB::table('site')->first()->supported_locales |
| 166 | : DB::table($contextDao->settingsTableName) |
| 167 | ->where($contextDao->primaryKeyColumn, $row->context_id) |
| 168 | ->where('setting_name', 'supportedLocales') |
| 169 | ->value('setting_value'); |
| 170 | |
| 171 | $rows = DB::table($this->defaultTable) |
| 172 | ->where('email_key', '=', $emailTemplate->getData('key')) |
| 173 | ->whereIn('locale', json_decode($supportedLocalesJson, true)) |
| 174 | ->get(); |
| 175 | |
| 176 | $props = ['name', 'subject', 'body']; |
| 177 | |
| 178 | $rows->each(function ($row) use ($emailTemplate, $schema, $props) { |
| 179 | foreach ($props as $prop) { |
| 180 | // Don't allow default data to override custom template data |
| 181 | if ($emailTemplate->getData($prop, $row->locale)) { |
| 182 | continue; |
| 183 | } |
| 184 | $emailTemplate->setData( |
| 185 | $prop, |
| 186 | $this->convertFromDB( |
| 187 | $row->{$prop}, |
| 188 | $schema->properties->{$prop}->type |
| 189 | ), |
| 190 | $row->locale |
| 191 | ); |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | return $emailTemplate; |
| 196 | } |
| 157 | public function fromRow(object $row): EmailTemplate |
| 158 | { |
| 159 | /** @var EmailTemplate $emailTemplate */ |
| 160 | $emailTemplate = parent::fromRow($row); |
| 161 | $schema = $this->schemaService->get($this->schema); |
| 162 | $contextDao = Application::getContextDAO(); |
| 163 | |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 165 | ? DB::table('site')->first()->supported_locales |
| 166 | : DB::table($contextDao->settingsTableName) |
| 164 | $supportedLocalesJson = $row->context_id === PKPApplication::SITE_CONTEXT_ID |
| 165 | ? DB::table('site')->first()->supported_locales |
| 166 | : DB::table($contextDao->settingsTableName) |
| 167 | ->where($contextDao->primaryKeyColumn, $row->context_id) |
| 168 | ->where('setting_name', 'supportedLocales') |
| 169 | ->value('setting_value'); |
| 170 | |
| 171 | $rows = DB::table($this->defaultTable) |
| 172 | ->where('email_key', '=', $emailTemplate->getData('key')) |
| 173 | ->whereIn('locale', json_decode($supportedLocalesJson, true)) |
| 174 | ->get(); |
| 175 | |
| 176 | $props = ['name', 'subject', 'body']; |
| 177 | |
| 178 | $rows->each(function ($row) use ($emailTemplate, $schema, $props) { |
| 179 | foreach ($props as $prop) { |
| 180 | // Don't allow default data to override custom template data |
| 181 | if ($emailTemplate->getData($prop, $row->locale)) { |
| 182 | continue; |
| 183 | } |
| 184 | $emailTemplate->setData( |
| 185 | $prop, |
| 186 | $this->convertFromDB( |
| 187 | $row->{$prop}, |
| 188 | $schema->properties->{$prop}->type |
| 189 | ), |
| 190 | $row->locale |
| 191 | ); |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | return $emailTemplate; |
| 196 | } |
| 133 | public function getByKey(int $contextId, string $key): ?EmailTemplate |
| 134 | { |
| 135 | $results = Repo::emailTemplate()->getCollector($contextId) |
| 136 | ->filterByKeys([$key]) |
| 137 | ->getMany(); |
| 138 | |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 140 | } |
| 133 | public function getByKey(int $contextId, string $key): ?EmailTemplate |
| 134 | { |
| 135 | $results = Repo::emailTemplate()->getCollector($contextId) |
| 136 | ->filterByKeys([$key]) |
| 137 | ->getMany(); |
| 138 | |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 139 | return $results->isNotEmpty() ? $results->first() : null; |
| 140 | } |
| 145 | public function getCount(Collector $query): int |
| 146 | { |
| 147 | return $query |
| 148 | ->getQueryBuilder() |
| 149 | ->getCountForPagination(); |
| 150 | } |
| 226 | return 'registry/emailTemplates.xml'; |
| 227 | } |
| 117 | public function getMany(Collector $query): LazyCollection |
| 118 | { |
| 119 | $rows = $query |
| 120 | ->getQueryBuilder() |
| 121 | ->get(); |
| 122 | |
| 123 | return LazyCollection::make(function () use ($rows) { |
| 124 | foreach ($rows as $row) { |
| 125 | yield $this->fromRow($row); |
| 126 | } |
| 127 | }); |
| 128 | } |
| 65 | return 'context_id'; |
| 66 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 437 | $key = uniqid(); |
| 438 | } |
| 439 | |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 437 | $key = uniqid(); |
| 438 | } |
| 439 | |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 437 | $key = uniqid(); |
| 438 | } |
| 439 | |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 431 | protected function getUniqueKey(EmailTemplate $emailTemplate): string |
| 432 | { |
| 433 | $key = (string) Str::of($emailTemplate->getLocalizedData('name')) |
| 434 | ->ascii()->kebab()->limit(30, '')->replaceMatches('[^a-z0-9\-\_.]', ''); |
| 435 | |
| 436 | if (!$key) { |
| 440 | $emailTemplate = $this->getByKey($emailTemplate->getData('contextId'), $key); |
| 441 | |
| 442 | $i = 0; |
| 443 | while ($emailTemplate) { |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 444 | $key = $i ? (substr($key, 0, -1) . $i) : ($key . $i); |
| 443 | while ($emailTemplate) { |
| 449 | return $key; |
| 450 | } |
| 87 | public function insert(EmailTemplate $object): string |
| 88 | { |
| 89 | if (!$object->getData('key')) { |
| 90 | $object->setData('key', $this->getUniqueKey($object)); |
| 91 | } |
| 92 | parent::_insert($object); |
| 92 | parent::_insert($object); |
| 93 | return $object->getData('key'); |
| 94 | } |
| 87 | public function insert(EmailTemplate $object): string |
| 88 | { |
| 89 | if (!$object->getData('key')) { |
| 92 | parent::_insert($object); |
| 93 | return $object->getData('key'); |
| 94 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 361 | throw new Exception('Unable to install email templates.'); |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 371 | if (!$alternateTo) { |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 356 | public function installAlternateEmailTemplates(int $contextId, ?string $emailKey = null): void |
| 357 | { |
| 358 | $xmlDao = new XMLDAO(); |
| 359 | $data = $xmlDao->parseStruct(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), ['email']); |
| 360 | if (!isset($data['email'])) { |
| 364 | foreach ($data['email'] as $entry) { |
| 364 | foreach ($data['email'] as $entry) { |
| 365 | $attrs = $entry['attributes']; |
| 366 | $alternateTo = $attrs['alternateTo'] ?? null; |
| 367 | |
| 368 | if ($emailKey && $emailKey != $attrs['key']) { |
| 369 | continue; |
| 370 | } |
| 371 | if (!$alternateTo) { |
| 372 | continue; |
| 373 | } |
| 374 | |
| 375 | $exists = DB::table($this->defaultTable) |
| 376 | ->where('email_key', $alternateTo) |
| 377 | ->exists(); |
| 378 | |
| 379 | if (!$exists) { |
| 380 | trigger_error( |
| 381 | 'Tried to install email template as an alternate to `' . $alternateTo . '`, but no default template exists with this key. Installing ' . $alternateTo . ' email template first', |
| 382 | E_USER_WARNING |
| 383 | ); |
| 384 | $this->installEmailTemplates(Repo::emailTemplate()->dao->getMainEmailTemplatesFilename(), [], $alternateTo); |
| 385 | } |
| 386 | |
| 387 | DB::table($this->table)->insert([ |
| 388 | 'email_key' => $attrs['key'], |
| 389 | 'context_id' => $contextId, |
| 390 | 'alternate_to' => $attrs['alternateTo'], |
| 391 | ]); |
| 392 | } |
| 393 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 305 | return false; |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 317 | if ($name && $subject && $body) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 297 | public function installEmailTemplateLocaleData( |
| 298 | string $templatesFile, |
| 299 | array $locales = [], |
| 300 | ?string $emailKey = null |
| 301 | ): bool { |
| 302 | $xmlDao = new XMLDAO(); |
| 303 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 304 | if (!isset($data['email'])) { |
| 308 | foreach ($data['email'] as $entry) { |
| 308 | foreach ($data['email'] as $entry) { |
| 309 | $attrs = $entry['attributes']; |
| 310 | if ($emailKey && $emailKey != $attrs['key']) { |
| 311 | continue; |
| 312 | } |
| 313 | |
| 314 | $name = $attrs['name'] ?? null; |
| 315 | $subject = $attrs['subject'] ?? null; |
| 316 | $body = $attrs['body'] ?? null; |
| 317 | if ($name && $subject && $body) { |
| 318 | foreach ($locales as $locale) { |
| 319 | DB::table($this->defaultTable) |
| 320 | ->where('email_key', $attrs['key']) |
| 321 | ->where('locale', $locale) |
| 322 | ->delete(); |
| 323 | |
| 324 | $previous = Locale::getMissingKeyHandler(); |
| 325 | Locale::setMissingKeyHandler(fn (string $key): string => ''); |
| 326 | $translatedName = $name ? __($name, [], $locale) : $attrs['key']; |
| 327 | $translatedSubject = __($subject, [], $locale); |
| 328 | $translatedBody = __($body, [], $locale); |
| 329 | Locale::setMissingKeyHandler($previous); |
| 330 | if ($translatedSubject !== null && $translatedBody !== null) { |
| 331 | DB::table($this->defaultTable)->insert([ |
| 332 | 'email_key' => $attrs['key'], |
| 333 | 'locale' => $locale, |
| 334 | 'name' => $translatedName, |
| 335 | 'subject' => $this->renameApplicationVariables($translatedSubject), |
| 336 | 'body' => $this->renameApplicationVariables($translatedBody), |
| 337 | ]); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | return true; |
| 343 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 249 | return false; |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 255 | $siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */ |
| 256 | $site = $siteDao->getSite(); /** @var Site $site */ |
| 257 | $locales = $site->getInstalledLocales(); |
| 258 | } |
| 259 | |
| 260 | // filter out any invalid locales that is not supported by site |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 263 | $locales = array_diff($locales, $invalidLocales); |
| 264 | } |
| 265 | |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 240 | public function installEmailTemplates( |
| 241 | string $templatesFile, |
| 242 | array $locales = [], |
| 243 | ?string $emailKey = null, |
| 244 | bool $skipExisting = false |
| 245 | ): bool { |
| 246 | $xmlDao = new XMLDAO(); |
| 247 | $data = $xmlDao->parseStruct($templatesFile, ['email']); |
| 248 | if (!isset($data['email'])) { |
| 253 | $locales = array_filter(array_map('trim', $locales)); |
| 254 | if (empty($locales)) { |
| 261 | $allLocales = array_keys(Locale::getLocales()); |
| 262 | if (!empty($invalidLocales = array_diff($locales, $allLocales))) { |
| 266 | foreach ($data['email'] as $entry) { |
| 266 | foreach ($data['email'] as $entry) { |
| 267 | $attrs = $entry['attributes']; |
| 268 | if ($emailKey && $emailKey != $attrs['key']) { |
| 269 | continue; |
| 270 | } |
| 271 | if ($skipExisting && $this->defaultTemplateIsInstalled($attrs['key'])) { |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Add localized data |
| 276 | $this->installEmailTemplateLocaleData($templatesFile, $locales, $attrs['key']); |
| 277 | |
| 278 | if (isset($attrs['alternateTo'])) { |
| 279 | $contextIds = app()->get('context')->getIds(); |
| 280 | foreach ($contextIds as $contextId) { |
| 281 | $this->installAlternateEmailTemplates($contextId, $attrs['key']); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 73 | return app(EmailTemplate::class); |
| 74 | } |
| 398 | protected function renameApplicationVariables(string $localizedData): string |
| 399 | { |
| 400 | $map = $this->variablesToRename(); |
| 401 | if (empty($map)) { |
| 402 | return $localizedData; |
| 398 | protected function renameApplicationVariables(string $localizedData): string |
| 399 | { |
| 400 | $map = $this->variablesToRename(); |
| 401 | if (empty($map)) { |
| 405 | $variables = []; |
| 406 | $replacements = []; |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 408 | $variables[] = '/\{\$' . $key . '\}/'; |
| 409 | $replacements[] = '{$' . $value . '}'; |
| 410 | } |
| 411 | |
| 412 | return preg_replace($variables, $replacements, $localizedData); |
| 413 | } |
| 398 | protected function renameApplicationVariables(string $localizedData): string |
| 399 | { |
| 400 | $map = $this->variablesToRename(); |
| 401 | if (empty($map)) { |
| 405 | $variables = []; |
| 406 | $replacements = []; |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 408 | $variables[] = '/\{\$' . $key . '\}/'; |
| 409 | $replacements[] = '{$' . $value . '}'; |
| 410 | } |
| 411 | |
| 412 | return preg_replace($variables, $replacements, $localizedData); |
| 413 | } |
| 398 | protected function renameApplicationVariables(string $localizedData): string |
| 399 | { |
| 400 | $map = $this->variablesToRename(); |
| 401 | if (empty($map)) { |
| 405 | $variables = []; |
| 406 | $replacements = []; |
| 407 | foreach ($map as $key => $value) { |
| 407 | foreach ($map as $key => $value) { |
| 408 | $variables[] = '/\{\$' . $key . '\}/'; |
| 409 | $replacements[] = '{$' . $value . '}'; |
| 410 | } |
| 411 | |
| 412 | return preg_replace($variables, $replacements, $localizedData); |
| 413 | } |
| 99 | public function update(EmailTemplate $object) |
| 100 | { |
| 101 | parent::_update($object); |
| 102 | } |
| 422 | return []; |
| 423 | } |